home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / makeBrushSpring.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  5.3 KB  |  162 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  1998
  22. //  Author:         DRB
  23. //
  24. global proc makeBrushSpring( 
  25. float $defStiff, float $defDamp, float $defTravel, int $startFrame )
  26. {
  27.     int       $i;
  28.     string $brushes[];
  29.  
  30.     $brushes = getSelectedBrushes();
  31.     int $numBrushes = size( $brushes );
  32.  
  33.     if( $numBrushes == 0 )
  34.     {
  35.         warning( "No brushes or strokes selected!" );
  36.         return;
  37.     }
  38.  
  39.     for( $i = 0; $i < $numBrushes; $i++ )
  40.     {
  41.         string $brush = $brushes[$i];
  42.         string $stroke[] = `listConnections ( $brush + ".outBrush")`;
  43.         if( size( $stroke ) > 0 )
  44.         {
  45.             string $curve[] = `listConnections ( $stroke[0] + ".pathCurve[0].curve")`;
  46.             if( size( $curve ) > 0 )
  47.             {
  48.                 if( `nodeType $curve[0]` == "curveFromSurfaceCoS")
  49.                 {
  50.                     $curve = `listConnections ( $curve[0] + ".curveOnSurface")`;
  51.                     if( size( $curve ) <= 0 )
  52.                     {
  53.                         continue;
  54.                     }
  55.                 }
  56.  
  57.                 // For multiple invokations we should probably try to reuse
  58.                 // existing pointOnCurve nodes, instead of letting them pile
  59.                 // up.
  60.                 string $poc = `pointOnCurve -ch on -parameter 0.5 $curve[0]`;
  61.  
  62.                 if ( !objExists( $curve[0] + ".lastWX" ) )
  63.                 {
  64.                     addAttr -sn lwx -ln lastWX -dv 0 $curve[0];
  65.                 }
  66.                 else
  67.                 {
  68.                     string $expNode[] = `listConnections ($curve[0] + ".lastWX")`;
  69.                     if( size( $expNode ) > 0 )
  70.                     {
  71.                         // This should be another spring expression Node 
  72.                         // We delete it to make way for the new one
  73.                         delete $expNode[0];
  74.                     }
  75.                 }
  76.                 if ( !objExists( $curve[0] + ".lastWY" ) )
  77.                 {
  78.                     addAttr -sn lwy -ln lastWY -dv 0 $curve[0];
  79.                 }
  80.                 if ( !objExists( $curve[0] + ".lastWZ" ) )
  81.                 {
  82.                     addAttr -sn lwz -ln lastWZ -dv 0 $curve[0];
  83.                 }
  84.                 if ( !objExists( $curve[0] + ".lastVX" ) )
  85.                 {
  86.                     addAttr -sn lvx -ln lastVX -dv 0 $curve[0];
  87.                 }
  88.                 if ( !objExists( $curve[0] + ".lastVY" ) )
  89.                 {
  90.                     addAttr -sn lvy -ln lastVY -dv 0 $curve[0];
  91.                 }
  92.                 if ( !objExists( $curve[0] + ".lastVZ" ) )
  93.                 {
  94.                     addAttr -sn lvz -ln lastVZ -dv 0 $curve[0];
  95.                 }
  96.                 if ( !objExists( $brush + ".springStiffness" ) ) 
  97.                 {
  98.                     addAttr -sn sst -ln springStiffness -dv $defStiff -min 0 -max 1 $brush;
  99.                 }
  100.                 else
  101.                 {
  102.                     setAttr  ($brush + ".springStiffness") $defStiff;
  103.                 }
  104.                 if ( !objExists( $brush + ".springDamp" ) ) 
  105.                 {
  106.                     addAttr -sn sdp -ln springDamp -dv $defDamp -min 0 -max 1 $brush;
  107.                 }
  108.                 else
  109.                 {
  110.                     setAttr  ($brush + ".springDamp") $defDamp;
  111.                 }
  112.                 if ( !objExists( $brush + ".springTravel" ) ) 
  113.                 {
  114.                     addAttr -sn spt -ln springTravel -dv $defTravel -min 0 -max 100 $brush;
  115.                 }
  116.                 else
  117.                 {
  118.                     setAttr  ($brush + ".springTravel") $defTravel;
  119.                 }
  120.                 string $expStr = "";
  121.  
  122.                 $expStr = $expStr + (
  123.                     "float $px = " + $poc + ".positionX;\n"
  124.                     + "float $py = " + $poc + ".positionY;\n"
  125.                     + "float $pz = " + $poc + ".positionZ;\n"
  126.                     + "float $wx = " + $curve[0] + ".lastWX;\n"
  127.                     + "float $wy = " + $curve[0] + ".lastWY;\n"
  128.                     + "float $wz = " + $curve[0] + ".lastWZ;\n"
  129.                     + "float $vx = " + $curve[0] + ".lastVX;\n"
  130.                     + "float $vy = " + $curve[0] + ".lastVY;\n"
  131.                     + "float $vz = " + $curve[0] + ".lastVZ;\n"
  132.                     + "float $stiff = " + $brush + ".springStiffness;\n"
  133.                     + "float $istiff = 1-$stiff;\n"
  134.                     + "float $damp = 1 - " + $brush + ".springDamp;\n"
  135.                     + "float $travel = " + $brush + ".springTravel;\n"
  136.                     + "float $fx = 0; float $fy = 0; float $fz = 0;\n"
  137.                     + "if( frame > " + ($startFrame + 1) + " ){\n"
  138.                     + "     $fx = " + $brush + ".uniformForceX * $istiff + $stiff * ($wx - $px) * $travel + $vx;\n"
  139.                     + "     $fy = " + $brush + ".uniformForceY * $istiff + $stiff * ($wy - $py) * $travel + $vy;\n"
  140.                     + "     $fz = " + $brush + ".uniformForceZ * $istiff + $stiff * ($wz - $pz) * $travel + $vz;\n"
  141.                     + "  " + $curve[0] +".lastVX = $vx * $damp -$fx * $stiff;\n"
  142.                     + "  " + $curve[0] +".lastVY = $vy * $damp -$fy * $stiff;\n"
  143.                     + "  " + $curve[0] +".lastVZ = $vz * $damp -$fz * $stiff;\n"
  144.                     + "}else{\n"
  145.                     + "  " + $curve[0] +".lastVX = 0;\n"
  146.                     + "  " + $curve[0] +".lastVY = 0;\n"
  147.                     + "  " + $curve[0] +".lastVZ = 0;\n"
  148.                     + "}\n"
  149.                     + $brush + ".uniformForceX = $fx;\n"
  150.                     + $brush + ".uniformForceY = $fy;\n"
  151.                     + $brush + ".uniformForceZ = $fz;\n"
  152.                     + $curve[0] +".lastWX = $px;\n"
  153.                     + $curve[0] +".lastWY = $py;\n"
  154.                     + $curve[0] +".lastWZ = $pz;\n" );
  155.                 expression -s $expStr;
  156.             }
  157.         }
  158.     }
  159.     
  160. }
  161.  
  162.